﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria.GameContent;

namespace Terraria.ModLoader
{
	// Token: 0x020001D7 RID: 471
	public class ModDust
	{
		// Token: 0x17000163 RID: 355
		// (get) Token: 0x0600134A RID: 4938 RVA: 0x0000FCF8 File Offset: 0x0000DEF8
		// (set) Token: 0x0600134B RID: 4939 RVA: 0x0000FD00 File Offset: 0x0000DF00
		public string Name { get; internal set; }

		// Token: 0x17000164 RID: 356
		// (get) Token: 0x0600134C RID: 4940 RVA: 0x0000FD09 File Offset: 0x0000DF09
		// (set) Token: 0x0600134D RID: 4941 RVA: 0x0000FD11 File Offset: 0x0000DF11
		public Texture2D Texture { get; internal set; }

		// Token: 0x17000165 RID: 357
		// (get) Token: 0x0600134E RID: 4942 RVA: 0x0000FD1A File Offset: 0x0000DF1A
		// (set) Token: 0x0600134F RID: 4943 RVA: 0x0000FD22 File Offset: 0x0000DF22
		public Mod mod { get; internal set; }

		// Token: 0x17000166 RID: 358
		// (get) Token: 0x06001350 RID: 4944 RVA: 0x0000FD2B File Offset: 0x0000DF2B
		// (set) Token: 0x06001351 RID: 4945 RVA: 0x0000FD33 File Offset: 0x0000DF33
		public int Type { get; internal set; }

		// Token: 0x17000167 RID: 359
		// (get) Token: 0x06001352 RID: 4946 RVA: 0x0000FD3C File Offset: 0x0000DF3C
		internal static int DustCount
		{
			get
			{
				return ModDust.nextDust;
			}
		}

		// Token: 0x06001353 RID: 4947 RVA: 0x0000FD43 File Offset: 0x0000DF43
		public static ModDust GetDust(int type)
		{
			if (type < 275 || type >= ModDust.DustCount)
			{
				return null;
			}
			return ModDust.dusts[type - 275];
		}

		// Token: 0x06001354 RID: 4948 RVA: 0x004105F0 File Offset: 0x0040E7F0
		internal static int ReserveDustID()
		{
			int result = ModDust.nextDust;
			ModDust.nextDust++;
			return result;
		}

		// Token: 0x06001355 RID: 4949 RVA: 0x00410610 File Offset: 0x0040E810
		internal static void ResizeArrays()
		{
			Array.Resize<bool>(ref ChildSafety.SafeDust, ModDust.nextDust);
			for (int i = 275; i < ModDust.nextDust; i++)
			{
				ChildSafety.SafeDust[i] = true;
			}
		}

		// Token: 0x06001356 RID: 4950 RVA: 0x0000FD68 File Offset: 0x0000DF68
		internal static void Unload()
		{
			ModDust.dusts.Clear();
			ModDust.nextDust = 275;
		}

		// Token: 0x06001357 RID: 4951 RVA: 0x00410648 File Offset: 0x0040E848
		internal static void SetupDust(Dust dust)
		{
			ModDust dust2 = ModDust.GetDust(dust.type);
			if (dust2 != null)
			{
				dust.frame.X = 0;
				dust.frame.Y = dust.frame.Y % 30;
				dust2.OnSpawn(dust);
			}
		}

		// Token: 0x06001358 RID: 4952 RVA: 0x00410688 File Offset: 0x0040E888
		internal static void SetupUpdateType(Dust dust)
		{
			ModDust dust2 = ModDust.GetDust(dust.type);
			if (dust2 != null && dust2.updateType >= 0)
			{
				dust.realType = dust.type;
				dust.type = dust2.updateType;
			}
		}

		// Token: 0x06001359 RID: 4953 RVA: 0x0000FD7E File Offset: 0x0000DF7E
		internal static void TakeDownUpdateType(Dust dust)
		{
			if (dust.realType >= 0)
			{
				dust.type = dust.realType;
				dust.realType = -1;
			}
		}

		// Token: 0x0600135A RID: 4954 RVA: 0x004106C8 File Offset: 0x0040E8C8
		internal void Draw(Dust dust, Color alpha, float scale)
		{
			Main.spriteBatch.Draw(this.Texture, dust.position - Main.screenPosition, new Rectangle?(dust.frame), alpha, dust.rotation, new Vector2(4f, 4f), scale, SpriteEffects.None, 0f);
			if (dust.color != default(Color))
			{
				Main.spriteBatch.Draw(this.Texture, dust.position - Main.screenPosition, new Rectangle?(dust.frame), dust.GetColor(alpha), dust.rotation, new Vector2(4f, 4f), scale, SpriteEffects.None, 0f);
			}
			if (alpha == Color.Black)
			{
				dust.active = false;
			}
		}

		// Token: 0x0600135B RID: 4955 RVA: 0x0000FD9C File Offset: 0x0000DF9C
		public virtual bool Autoload(ref string name, ref string texture)
		{
			return this.mod.Properties.Autoload;
		}

		// Token: 0x0600135C RID: 4956 RVA: 0x00006B58 File Offset: 0x00004D58
		public virtual void SetDefaults()
		{
		}

		// Token: 0x0600135D RID: 4957 RVA: 0x00006B58 File Offset: 0x00004D58
		public virtual void OnSpawn(Dust dust)
		{
		}

		// Token: 0x0600135E RID: 4958 RVA: 0x00008CF7 File Offset: 0x00006EF7
		public virtual bool Update(Dust dust)
		{
			return true;
		}

		// Token: 0x0600135F RID: 4959 RVA: 0x0000ADF8 File Offset: 0x00008FF8
		public virtual bool MidUpdate(Dust dust)
		{
			return false;
		}

		// Token: 0x06001360 RID: 4960 RVA: 0x00404FFC File Offset: 0x004031FC
		public virtual Color? GetAlpha(Dust dust, Color lightColor)
		{
			return null;
		}

		// Token: 0x0400145E RID: 5214
		private static int nextDust = 275;

		// Token: 0x0400145F RID: 5215
		internal static readonly IList<ModDust> dusts = new List<ModDust>();

		// Token: 0x04001460 RID: 5216
		public int updateType = -1;
	}
}
